/**
 * 
 */
package com.orcwar.engine.units;

import com.orcwar.engine.OWMap;
import com.orcwar.engine.OWPlayer;
import com.orcwar.engine.OWTile;
import com.orcwar.engine.OWUnit;
import com.orcwar.engine.tile.OWAttackTile;
import com.orcwar.enums.OWAttackTileTypeEnum;
import com.orcwar.enums.SpriteEnum;

/**
 * @author Callil
 *
 */
public class OWHacheur extends OWUnit {

	/**
	 * Constructor
	 * @param id the id
	 */
	public OWHacheur(int id, OWPlayer player) {
		super(id, player, SpriteEnum.UNIT_HACHEUR);
		
		//The hacheur can attack 2 times
		setAttackPoints(2);
		setMaxAttackPoints(2);
		//and move up to 5 tiles
		setMaxMovePoints(5);
		setMovePoints(5);
		
	}
	
	@Override
	public OWAttackTile[] getGlobalMandatoryAvailableTiles(OWMap map, OWTile fromTile) {
		return null;
	}

	@Override
	public boolean isRangeOk(int srcX, int srcY, int targetX, int targetY) {
		//The hacheur can attack all around him at only 1 tile of distance
		// _ _ _ _ _
		//| | | | | |
		//| |x|x|x| |
		//| |x|H|x| |
		//| |x|x|x| |
		//|_|_|_|_|_|
		
		boolean xOk = Math.abs(srcX - targetX) <= 1;
		boolean yOk = Math.abs(srcY - targetY) <= 1;
		boolean sameTile = (srcX == targetX) && (srcY == targetY);
		return xOk && yOk && !sameTile;
	}

	@Override
	public OWAttackTile[][] getAttackTiles(OWMap map, OWTile fromTile) {
		//The bouclieur can attack all around him at only 1 tile of distance
		// _ _ _ _ _
		//| | | | | |
		//| |x|x|x| |
		//| |x|H|x| |
		//| |x|x|x| |
		//|_|_|_|_|_|
		int x;
		int y;
		if (fromTile != null) {
			x = fromTile.getX();
			y = fromTile.getY();
		} else {
			x= this.getTile().getX();
			y = this.getTile().getY();
		}
		OWAttackTile[][] attackTiles = new OWAttackTile[][]{ 
				new OWAttackTile[] {OWAttackTile.create(map.getTile(x-1, y-1), OWAttackTileTypeEnum.ATTACKABLE)},
				new OWAttackTile[] {OWAttackTile.create(map.getTile(x-1, y), OWAttackTileTypeEnum.ATTACKABLE)}, 
				new OWAttackTile[] {OWAttackTile.create(map.getTile(x-1, y+1), OWAttackTileTypeEnum.ATTACKABLE)},
				new OWAttackTile[] {OWAttackTile.create(map.getTile(x, y-1), OWAttackTileTypeEnum.ATTACKABLE)}, 
				new OWAttackTile[] {OWAttackTile.create(map.getTile(x, y+1), OWAttackTileTypeEnum.ATTACKABLE)},
				new OWAttackTile[] {OWAttackTile.create(map.getTile(x+1, y-1), OWAttackTileTypeEnum.ATTACKABLE)},
				new OWAttackTile[] {OWAttackTile.create(map.getTile(x+1, y), OWAttackTileTypeEnum.ATTACKABLE)},
				new OWAttackTile[] {OWAttackTile.create(map.getTile(x+1, y+1), OWAttackTileTypeEnum.ATTACKABLE)}};

		return attackTiles;
	}

}
